package com.noahplat.common.utils;

import io.netty.channel.ChannelHandlerContext;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class GatewayService {
    private static Map<String, ChannelHandlerContext> map = new ConcurrentHashMap<>();

    public static void addGatewayChannel(String id, ChannelHandlerContext ctx){
        map.put(id, ctx);
    }

    public static Map<String, ChannelHandlerContext> getChannels(){
        return map;
    }

    public static ChannelHandlerContext getGatewayChannel(String id){
        return map.get(id);
    }

    public static void removeGatewayChannel(ChannelHandlerContext ctx){
        Collection<ChannelHandlerContext> values = map.values();
        while (true == values.contains(ctx)){
            values.remove(ctx);
        }
    }
}
